import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("//listfotos")
public class ListVeiculoFotosServlet extends HttpServlet {
   
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "sa");
            PreparedStatement ps = con.prepareStatement("select v.placa, v.ano, v.foto, v.acessorio, deref(cor).descricao as cor, deref(modelo).descricao as mod from tb_veiculo v");
            ResultSet rs = ps.executeQuery();
            out.println("<h1>Photos</h1>");
            
            
            while ( rs.next()) {
                  //out.println("<h4>" + rs.getString("titulo") + "</h4>");
                  //out.println("<img width='600' height='600' src=displayphoto?cod=" +  rs.getString("cod") + "></img> <p/>");
            	out.println("<center>");
                out.println("<div style='float:left; width:33%'>");
                out.println("<table>");
            	  out.println("<tr><td align='left'>");      
                  out.println("<img width='238' height='228' src=displayfoto?placa="+rs.getObject("placa")+ "></img>");
                  out.println("</td></tr>");
                  out.println("<tr><td align='left'>");
                  out.println(rs.getObject("ano")+"<br>");
                  out.println(rs.getObject("acessorio")+"<br>");
                  out.println(rs.getObject("cor")+"<br>");
                  out.println(rs.getObject("mod"));	
                  out.println("</td></tr>");

                  out.println("</table>");
                  out.println("</div>");
                  out.println("</center>");
                  
            }
            

            con.close();
        }
        catch(Exception ex) {

        }
        finally { 
            out.close();
        }
    } 

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
}